/*
* ThreeLinksController.java
* Created on  2015/7/27 15:12
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/7/27       longshihui    初始版本
*
*/

package com.infitecs.eyas.tools;

import com.infitecs.eyas.expression.service.ToolExpressionService;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.tool.Inner;
import com.infitecs.eyas.tool.ThreeLinks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/tools/threeLinks")
public class ThreeLinksController {

    @Autowired
    private ToolExpressionService toolExpressionService;

    @Autowired
    private SessionService sessionService;

    @RequestMapping("")
    public String getPage(){
        sessionService.setEnvironment('T');
        return "tools/threeLinks";
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public void update(ThreeLinks threeLinks){
        toolExpressionService.updateToolsParam(threeLinks);
    }

    @RequestMapping(value = "/clean", method = RequestMethod.POST)
    @ResponseBody
    public void clean() {
        toolExpressionService.clearMap();
        toolExpressionService.clearResultMap();
    }

    @RequestMapping(value = "/calAll/{type}",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Double> calAll(@PathVariable("type")int type){
        Map<String,Double> re = new HashMap<>();
        if (!toolExpressionService.hasParamValue("E15")) {
            re.put("E15", toolExpressionService.calculate("TE15"));
        }
        if (!toolExpressionService.hasParamValue("E172")) {
            re.put("E172", toolExpressionService.calculate("TE172"));
        }
        if (!toolExpressionService.hasParamValue("E181")) {
            re.put("E181", toolExpressionService.calculate("TE181"));
        }
        re.put("E19", toolExpressionService.calculate("TE19"));
        re.put("E21", toolExpressionService.calculate("TE21"));
        if (type == 1) {
            re.put("E185", toolExpressionService.calculate("TE185"));
            re.put("E186", toolExpressionService.calculate("TE186"));
            re.put("E187", toolExpressionService.calculate("TE187"));
            re.put("E188", toolExpressionService.calculate("TE188"));
            re.put("E189", toolExpressionService.calculate("TE189"));
            re.put("E190", toolExpressionService.calculate("TE190"));
//            toolExpressionService.getResult().put("p", re.get("E19"));
//            toolExpressionService.getResult().put("z",re.get("E210"));
//            toolExpressionService.getResult().put("lost",re.get("E210") * re.get("E19"));
        }else{
            re.put("E192", toolExpressionService.calculate("TE192"));
            re.put("E193", toolExpressionService.calculate("TE193"));
            re.put("E194", toolExpressionService.calculate("TE194"));
            re.put("E195", toolExpressionService.calculate("TE195"));
            re.put("E196", toolExpressionService.calculate("TE196"));
            re.put("E197", toolExpressionService.calculate("TE197"));
//            toolExpressionService.getResult().put("p", re.get("E19"));
//            toolExpressionService.getResult().put("z",re.get("E210"));
//            toolExpressionService.getResult().put("lost",re.get("E210") * re.get("E19"));
        }
        return re;
    }
}
